class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        size_t size = s.size();
        if(size == 0 || 1 == size) return size;
        char hash[50000] = {0};
        int res = 1;
        for(int left = 0,right = 0; right < size; ++right){
            hash[s[right]] += 1;
            while(hash[s[right]] > 1){
                hash[s[left++]] -= 1;
            }
            int len = right - left + 1;
            res = res>len ? res : len;
        }
        return res;
    }
};